<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Skornyakov Anatoliy
 * Date: 31.05.13
 * Time: 16:00
 * 
 */

class Zftest_View_Helper_PhoneElement extends Zend_View_Helper_FormElement
{
    const NAME_COUNTRY = 'country';

    const NAME_CITY    = 'city';

    const NAME_NUMBER  = 'number';

    const NAME_MORE    = 'more';

    private $_html = 'Код страны: %s - код города: %s - номер: %s - доп. номер: %s';

    public function phoneElement($name, $value = null, $attribs = null)
    {
        $countryValue = (isset($value[self::NAME_COUNTRY])) ? $value[self::NAME_COUNTRY] : '';
        $cityValue    = (isset($value[self::NAME_CITY]))    ? $value[self::NAME_CITY]    : '';
        $numberValue  = (isset($value[self::NAME_NUMBER]))  ? $value[self::NAME_NUMBER]  : '';
        $moreValue    = (isset($value[self::NAME_MORE]))    ? $value[self::NAME_MORE]    : '';

        $this->_html = sprintf($this->_html, $this->view->formText($name . '[' . self::NAME_COUNTRY . ']', $countryValue, $attribs),
            $this->view->formText($name . '[' . self::NAME_CITY . ']', $cityValue, $attribs),
            $this->view->formText($name . '[' . self::NAME_NUMBER . ']', $numberValue, $attribs),
            $this->view->formText($name . '[' . self::NAME_MORE . ']', $moreValue, $attribs));

        return $this->_html;
    }
}